package com.ge.med.cchelper.popup.job;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IDecoratorManager;
import org.eclipse.ui.PlatformUI;

import com.ge.med.cchelper.Constants;
import com.ge.med.cchelper.bean.CSession;
import com.ge.med.cchelper.util.ReourceHelper;

public abstract class BaseJob extends org.eclipse.core.runtime.jobs.Job {

	public CSession csession;
	public String sourceTempDir;
	public ReourceHelper resource;
	public String root;
	public String workDir = Constants.REMOTE_HOME;
	public String emptyDir;

	public BaseJob(String name) {
		super(name);
		resource = ReourceHelper.getResource();
		IProject project = ReourceHelper.getProject();
		csession = resource.getSession(project.getName());
		String loginpwd = csession.getLoginpwd();

		if (loginpwd != null) {
			root = (String) loginpwd + "/" + workDir;
		} else {
			root = "~/" + workDir;
		}
		sourceTempDir = root + "/"+Constants.VOB;
		emptyDir = root + "/"+Constants.EMPTYDIR+"/";
	}

	protected abstract IStatus start(IProgressMonitor arg0);

	protected IStatus run(IProgressMonitor arg0) {

		IStatus status = start(arg0);

		Display.getDefault().asyncExec(new Runnable() {
			public void run() {
				IDecoratorManager decoratorManager = PlatformUI.getWorkbench()
						.getDecoratorManager();
				decoratorManager.update("decorator.cchelper");
			}
		});

		return status;
	};

}
